package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IPermissionService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {
	
	@Autowired
	private IPermissionService permissionService;

	@RequestMapping("list")
	public String list(Model model, @ModelAttribute("qo")QueryObject qo){
		model.addAttribute("result", permissionService.query(qo));
		return "/permission/list";
	}
	@RequestMapping("reload")
	public String reload(Model model, @ModelAttribute("qo")QueryObject qo){
		permissionService.reload();
		return "redirect:/permission/list.do";
	}

	@RequestMapping("/delete")
	@ResponseBody
	public Object saveDelete(Long id){
		JSONResult result = new JSONResult();
		try {
			if(id != null){
                permissionService.deleteByPrimaryKey(id);
            }
		} catch (Exception e) {
			e.printStackTrace();
			result.mark(e.getMessage());
		}

		return result;
	}
}
